<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h:form id="form" enctype="multipart/form-data">
                <h2 class="title">Relatório BCI</h2>
                <p:growl id="messages" showDetail="false" autoUpdate="true"  /> 
                <br/>
                <p:panel id="fatorPanel" styleClass="container_24 clearfix withoutBorder">

                    <h4 class="title">Fator de Localização</h4>

                    <p:outputLabel value="Distrito" styleClass="grid_3" for="dInput" />
                    <p:inputText id="dInput" styleClass="grid_4" 
                                 value="#{managerPesquisarImovel.imovel.inscricaoCadastralD}" />

                    <p:outputLabel value="Setor" styleClass="grid_3" for="sInput" />
                    <p:inputText id="sInput" styleClass="grid_4" 
                                 value="#{managerPesquisarImovel.imovel.inscricaoCadastralS}" />

                    <p:outputLabel value="Quadra" styleClass="grid_3" for="qInput" />
                    <p:inputText id="qInput" styleClass="grid_4" 
                                 value="#{managerPesquisarImovel.imovel.inscricaoCadastralQuadra}" />
                    <div class="clear-both" />

                    <p:outputLabel value="Lote" styleClass="grid_3" for="lInput" />
                    <p:inputText id="lInput" styleClass="grid_4" 
                                 value="#{managerPesquisarImovel.imovel.inscricaoCadastralLote}" />

                    <p:outputLabel value="Unidade" styleClass="grid_3" for="uInput" />
                    <p:inputText id="uInput" styleClass="grid_4" 
                                 value="#{managerPesquisarImovel.imovel.inscricaoCadastralUnid}" />
                    <div class="clear-both" />
                </p:panel>


                <p:panel id="ownerPanel" styleClass="container_24 clearfix">

                    <h4 class="title">Proprietário</h4>

                    <p:outputLabel value="Proprietário: "  styleClass="grid_3"/>
                    <p:selectOneRadio id="typePerson" 
                                      value="#{managerPesquisarImovel.proprietario.tipoDocumento}" >  
                        <f:selectItems value="#{managerUtilitario.tipoDocumento}" />
                        <p:ajax event="change" update=":form:ownerPanel" />
                    </p:selectOneRadio>

                    <div class="clear"/>

                    <p:outputLabel id="typeDocumentLabel" 
                                   value="#{managerPesquisarImovel.proprietario.tipoDocumento}: " 
                                   styleClass="grid_3"/>

                    <f:validateBean disabled="true">
                        <p:inputMask id="typeDocumentInput" 
                                     value="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CPF' ? 
                                              managerPesquisarImovel.proprietario.cpf : managerPesquisarImovel.proprietario.cnpj}"
                                     mask="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CPF' ? 
                                             '999.999.999-99':'99.999.999/9999-99'}" 
                                     styleClass="grid_5" > 

                        </p:inputMask>
                    </f:validateBean>
                    <div class="clear"/>
                    <p:outputLabel value="Nome: " styleClass="grid_3" for="nomeInputText" 
                                   rendered="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CPF'}"/>
                    <p:inputText id="nomeInputText" styleClass="grid_19" 
                                 value="#{managerPesquisarImovel.proprietario.nome}" 
                                 rendered="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CPF'}" />

                    <p:outputLabel value="Fantasia: " styleClass="grid_3" for="nameFantasyInputText" 
                                   rendered="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CNPJ'}" />
                    <p:inputText id="nameFantasyInputText" styleClass="grid_19"
                                 value="#{managerPesquisarImovel.proprietario.nomeFantasia}" 
                                 rendered="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CNPJ'}" />

                </p:panel>

                <p:panel id="addressPanel" styleClass="container_24 clearfix ">

                    <h4 class="title">Endereço</h4>

                    <p:outputLabel value="CEP" styleClass="grid_3" for="cepInputMask" />
                    <p:inputMask id="cepInputMask" styleClass="grid_4" mask="99.999-999"
                                 value="#{managerPesquisarImovel.endereco.cep}" />
                    <div class="clear-both" />

                    <p:outputLabel value="Número" styleClass="grid_3" for="numInputText" />
                    <p:inputText id="numInputText" styleClass="grid_2"
                                 value="#{managerPesquisarImovel.endereco.numero}" />

                    <p:outputLabel value="Logradouro" styleClass="grid_4 alpha" for="patioInputText" />
                    <p:inputText id="patioInputText" styleClass="grid_13"
                                 value="#{managerPesquisarImovel.endereco.logradouro}" />

                    <div class="clear-both" />
                    <p:outputLabel value="Bairro" styleClass="grid_3" for="neighborhoodInputText" />
                    <p:inputText id="neighborhoodInputText" styleClass="grid_19"
                                 value="#{managerPesquisarImovel.endereco.bairro}" />

                </p:panel>

                <br/>
                <div class="buttonAction">
                    <p:commandButton title="Imprimir" icon="ui-icon-print" update="@form" 
                                     process="@form" oncomplete="dlgBCI.show()" value="Imprimir"/>
                    <p:commandButton title="Limpar" icon="ui-icon-clean" update="@form" 
                                     actionListener="#{managerPesquisarImovel.init()}"
                                     process="@form" value="Limpar"/>
                </div >
                <br/>

                <p:dialog id="bciDialog" header="Imprimir BCI" widgetVar="dlgBCI" modal="true" 
                          height="80" width="450" closable="true" resizable="false" closeOnEscape="true">

                    <p:outputLabel value="Deseja imprimir o BCI com todos os anexos ?" />

                    <div class="buttonAction">
                        <p:commandButton value="Sim" actionListener="#{managerPesquisarImovel.relatorioBCI(true)}"
                                         ajax="false" onclick="this.form.target='_blank'" update=":form:bciDialog"
                                         icon="ui-icon-check" immediate="true" onkeyup="dlgBCI.hide()"/>
                        <p:commandButton value="Não" actionListener="#{managerPesquisarImovel.relatorioBCI(false)}"
                                         ajax="false" onclick="this.form.target='_blank'" update=":form:bciDialog"
                                         icon="ui-icon-close" immediate="true" onkeyup="dlgBCI.hide()"/>
                    </div>
                </p:dialog>

            </h:form>
        </ui:define>
    </ui:composition>
</html>
